<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>解放军第三〇五医院</title>
<%@include file="/WEB-INF/templates/common/common.jsp"%>
<script type="text/javascript" src="${basePath}/static/page/js/jqPaginator.js"></script> 
<script  type="text/javascript" src="${basePath}/static/My97DatePicker/WdatePicker.js"></script>
<script  type="text/javascript" src="${basePath}/static/layer/layer.js"></script>
<link href="${basePath}/static/layer/layer_style.css" rel="stylesheet" type="text/css">
</head>
<body>

</head>
<body>
 <!--头部-->
 <%@include file="/WEB-INF/templates/common/header.jsp"%>

<!------导航条-->
 <%@include file="/WEB-INF/templates/common/navigation.jsp"%>
<div class="list_main lay_out">
<div class="list_DH">
<!--打印模块导航栏-->
 <%@include file="/WEB-INF/templates/common/printnav.jsp"%>
 </div>
 <div class="list_NR">
  <div class="loc">
   <h3>打印计费</h3>

  </div>
  <div class="list_con_table"> 
   <div class="search_table" style="position:relative">
    <ul>
    <li class="Label_1" style="width:15%;">病案所属人姓名：&nbsp;</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="10"  name='patientName' id='patientName' value='' /></li>
    <li class="Label_1"  style="width:15%;">病案所属人身份证：</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="20" name='patientCard' id='patientCard' value='' /></li>
    <li class="Label_1" style="width:10.7%">申请人姓名：&nbsp;</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="10" name='applyName' id='applyName' value='' /></li>
    <li class="Label_1" style="width:15%;">申请人身份证：</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="20" name='applyCard' id='applyCard' value='' /></li>
    <li class="Label_1" style="width:15%;">诊疗记录标示：&nbsp;</li>
    <li class="Label_2"><input type="text"  maxlength="12"class="input_box" id="medicalRecord"/></li>
	<li class="Label_1" style="width:10.7%;">申请时间：&nbsp;</li>
    <li class="Label_2"><input class="input_box" id="timeEnd" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" type="text"  name=''  value='' /></li>
	 <li class="Label_1" style="width:15%;">收费状态：&nbsp;</li>
	 <li style="width:285px" class="Label_3">
     <input type="radio" class="radio_cl" checked="checked" name='printCheck' id='' value='1' />未收费
     <input type="radio" class="radio_cl"  name='printCheck' id='' value='2' />预收费
       <input type="radio" class="radio_cl"  name='printCheck' id='' value='3' />已收费
    </li> 
    <li class="Label_5">
     <a onclick="queryPrintFeeMsg(0,10)">查询</a>
    </li>
    </ul>
   </div>
  </div>

 <table class="Search_tableList" cellpadding="0" cellspacing="0">
     
      <tr>
      <td class="tdLabel_4">序号</td>
      <td class="tdLabel_4">申请人</td>
      <td class="tdLabel_4">申请人身份证</td>
      <td class="tdLabel_4">申请诊疗记录份数</td>
      <td class="tdLabel_4">已打印诊疗记录份数</td>
      <td class="tdLabel_4">打印单价(单位页)</td>
      <td class="tdLabel_4">打印总页数</td>
      <td class="tdLabel_4">预交费用</td>
      <td class="tdLabel_4">打印总费用</td>
      <td class="tdLabel_4">收费状态</td>
      <td class="tdLabel_4">操作</td>
      </tr>
      <tbody id="tbody">

      </tbody>
     </table>
     <div class="pageList">
       <ul class="pagination clearfix" id="page_plus"></ul>
       <div class="pagination">
            <div>总共：<b id="totalPage">0</b> 条信息    当前页是第 <b id="currentPage">0/0</b>　页</div>
       </div>          
     </div>
     <!-- <div class="pages">
        <div id="Pagination"></div>
        <div class="searchPage">
          <span class="page-sum">共<strong id="ston_page_msg" class="allPage">0</strong>页</span>
          <span class="page-go">跳转<input type="text" class="number">页</span>
          <a href="javascript:;" class="page-btn">GO</a>
        </div>
     </div>
 -->
 	
 </div>
</div>
<!--页脚部分-->
 <%@include file="/WEB-INF/templates/common/footer.jsp"%>
 <script>
 	//查询打印申请信息
 	function queryPrintFeeMsg(pageNo,pageSize){
 		 var val=$('input:radio[name="printCheck"]:checked').val();
 		 var patientName=$("#patientName").val();
 		 var patientCard=$("#patientCard").val();
 		 var medicalRecord=$("#medicalRecord").val();
 		 var applyName=$("#applyName").val();
 		 var applyCard=$("#applyCard").val();
 		 
 		/*  if(!patientName && !patientCard && !medicalRecord && !applyName && !applyCard){
 			layer.alert("至少输入一个查询条件!",{icon:0});
 			return;
 		 } */
 		$.ajax({
 			type:"post",
 			url:"${basePath}/print/getPrintFeeMsg",
 			data:{patientName:patientName,patientCard:patientCard,status:val,
 				medicalRecord:medicalRecord,applyName:applyName,applyCard:applyCard,pageNo:pageNo,pageSize:pageSize},
 			success:function(data){
 				console.log(typeof(data))
 				var count =data.count;
 				/* page(pageNo,count); */
 				var printFeeList=data.printFeeMsgList;
 				/* console.log(printFeeList) */
 				if(data.listSize>0){
 					initPage(count,pageSize,pageNo+1)
 					var html="";
 					for(var i in  printFeeList){
 						var applyPrint=printFeeList[i];
 						html+="<tr>"+
 					     " <td class='tdLabel_5'>"+((parseInt(i)+1)+(parseInt(pageNo)*pageSize))+"</td>"+
 					     " <td class='tdLabel_5'>"+applyPrint.applyName+"</td>"+
 					    " <td class='tdLabel_5'>"+applyPrint.applyCard+"</td>"+
 					     " <td class='tdLabel_5'>"+applyPrint.applyCount+"</td>"+
 					     " <td class='tdLabel_5' >"+applyPrint.printCount+"</td>"+
 					     " <td class='tdLabel_5'>"+applyPrint.perPagePrice+"</td>"+
 					    " <td class='tdLabel_5'>"+(applyPrint.printCountPage!=undefined?applyPrint.printCountPage:0)+"</td>"+
 					   " <td class='tdLabel_5' id='perchargecount"+applyPrint.printFeeId+"'>"+(applyPrint.perchargeCount!=undefined?applyPrint.perchargeCount:0)+"</td>"+
 					  
 					  " <td class='tdLabel_5'>"+(applyPrint.printFee!=undefined?applyPrint.printFee:0)+"</td>"+
 					 " <td class='tdLabel_5' id='chargeStatus"+applyPrint.printFeeId+"'>"+getChargeStatus(applyPrint.chargeStatus)+"</td>"+
 					 " <td class='tdLabel_5'><a id='TC1' status='"+applyPrint.chargeStatus+"' printcount='"+applyPrint.printCount+"' applycount='"+applyPrint.applyCount+"'  onclick='updateChargeStatus("+applyPrint.printFeeId+",this)'>收费</a></td>"+
 					    "  </tr>";
 					    
 					}
 					$("#tbody").html(html);
 				}else{
 					layer.alert("数据为空!", {icon: 5});
 				}
 			}
 		})
 	}
 	

 	

 	
 	//审批状态
 	function getChargeStatus(status){
 		switch(status) {
 			case 1: 
 				return "未收费";
 			break; 
 			case 2: 
 				return "预收费";
 			break; 
 			case 3: 
 				return "已收费";
 			break; 
 			default: 
 				return "打印失败";
 		}
 	}
 	
 
 	
	//批量选中checkbox
 	function checkAll(obj){
 		var $this=$(obj);
 		if($this.is(':checked')){
 			$("input[type='checkbox'][name='checkOne']").each(function(){
 				$(this).attr("checked",true);
			});
 		}else{
 			$("input[type='checkbox'][name='checkOne']").each(function(){
 				$(this).attr("checked",false);
			});
 		}
 	} 
 	
 	//选中
 	function updateChargeStatus(printFeeId,obj){
			var $this=$(obj);
			var applycount=$this.attr("applycount");
			var printcount=$this.attr("printcount");
			var status=$this.attr("status");
			if(status==3){
				layer.alert("已经收费,请勿再次收取!", {icon: 2});
				return;
			}
			if(applycount!=printcount){
				layer.alert("打印份数与申请成功份数不一致，请打印全部完成后再进行收费!", {icon: 2});
				return;
			}else{
				$.ajax({
	 				type:"post",
	 				data:{printFeeId:printFeeId,status:3},
	 				url:"${basePath}/print/updateChargeStatus",
	 				success:function(data){
	 					if(data=="success"){
	 						$("#perchargecount"+printFeeId+"").html(0);
	 						$("#chargeStatus"+printFeeId+"").html("已收费");
	 						layer.alert("收费成功!", {icon: 1});
	 					}else{
	 						layer.alert("更新失败!", {icon: 2});
	 					}
	 				}
	 			});
			}
 		
 	
 	}
 	
 	
 	
 	function page(currentPage,totalCounts){
 		
 		var totalCounts = totalCounts;
 	 		var pageSize = 10;
 	 		var totalPages = Math.ceil(totalCounts/pageSize);
 	 		//var currentPage = 1;
 	 		$("#ston_page_msg").text(totalPages);
 	 		$(".number").keypress(function(event) {  
 	 			 var ev = event.which?event.which:window.event.keyCode;
 	 			  if(ev>=48&&ev<=57){
 	 				return true;  
 	 			  }else if(ev==8 || ev==13 || ev==46){
 	 				return true;  
 	 			  }else{
 	 				return false;
 	 			  } 
 	 		}).focus(function() {  
 	 			this.style.imeMode='disabled';  
 	 		});  
 	 		$("#Pagination").pagination(totalPages,{
 	 		current_page:currentPage,
 	 	  callback: function (page_index,jp) {
 	 	 	 //currentPage=page_index;
 	 		queryPrintFeeMsg(page_index,pageSize);
 	 	  } //PageCallback() 为翻页调用次函数。
 	 	  
 	 	  });
 		}
     
 	 //分页
	function initPage(totalCounts,pageSize,currentPage){
		 var visiblePages = 5;
		 var totalPages = Math.ceil(totalCounts/pageSize);
		 $("#totalPage").html(totalCounts);
		 if(totalCounts < 1){
			 	$("#currentPage").html(0+"/"+totalPages);
			 	$("#page_plus").html("");
			 	return;
		}
         $("#currentPage").html(currentPage+"/"+totalPages);
		 $('#page_plus').jqPaginator({

		        totalCounts: totalCounts,
		        pageSize:pageSize,
		        visiblePages: visiblePages,
		        currentPage: currentPage,

		        first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
		        prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
		        next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
		        last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
		        page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
		        onPageChange: function (page,type) {
		        	if(type !='init'){
		        	 queryPrintFeeMsg(page-1,pageSize);
		        	}
		        }
		    });

	}	
 
 </script>
</body>
</html>
